<?php

    require($_SERVER['DOCUMENT_ROOT']."/bootstrap.php");
    // Nếu đã đăng nhập thì chuyển sang index
    if($session_email != '')
        header('Location: /');
    
    $founduser=-1;
    if(!isset($_POST['button']))
    {
        $smarty->assign("founduser", $founduser);
        $smarty->display('../templates/login/index.tpl');
        die();
    }
    if(isset($_POST['button']))
    {
        $email=mysql_real_escape_string($_POST['email']);
        $pass=md5(mysql_real_escape_string($_POST['pass']));
        if($email && $pass)
        { 
            $founduser=0;
            $sql="select * from user where email='".$email."' and password='".$pass."'";
            $query=mysql_query($sql);
            if(mysql_num_rows($query) == 0)
            {
                $email='';
            }
            else
            {
                $row=mysql_fetch_array($query);
                $_SESSION['email'] = $row['email'];
                $founduser=1;
            }
            $smarty->assign("founduser",$founduser);
            $smarty->display('../templates/login/index.tpl');
        }
    }
?>